"""Custom exceptions for the CLU API service."""

from typing import Optional


class CLUServiceError(Exception):
    """Base exception for CLU service."""
    status_code: int = 500
    message: str = "An internal CLU service error occurred."

    def __init__(self, message: Optional[str] = None, status_code: Optional[int] = None):
        if message:
            self.message = message
        if status_code:
            self.status_code = status_code
        super().__init__(self.message)


class ProjectNotFoundError(CLUServiceError):
    """Raised when a project is not found."""
    status_code = 404
    message = "Project not found."


class ProjectExistsError(CLUServiceError):
    """Raised when attempting to create a project that already exists."""
    status_code = 409
    message = "Project already exists."


class TrainingError(CLUServiceError):
    """Raised when there's an error in training operations."""
    status_code = 500
    message = "An error occurred during training."


class DeploymentError(CLUServiceError):
    """Raised when there's an error in deployment operations."""
    status_code = 500
    message = "An error occurred during deployment."


class ModelNotFoundError(CLUServiceError):
    """Raised when a model is not found."""
    status_code = 404
    message = "Model not found."


class IntentNotFoundError(CLUServiceError):
    """Raised when an intent is not found."""
    status_code = 404
    message = "Intent not found."


class InvalidConfigError(CLUServiceError):
    """Raised when configuration is invalid."""
    status_code = 400
    message = "Invalid configuration provided."


class AnalysisError(CLUServiceError):
    """Raised when there's an error in conversation analysis."""
    status_code = 500
    message = "An error occurred during conversation analysis."


class EmptyMessageError(CLUServiceError):
    """Raised when message content is empty or missing."""
    status_code = 400
    message = "Message content cannot be empty."


class InvalidRequestBodyError(CLUServiceError):
    """Raised when request body is invalid or malformed."""
    status_code = 400
    message = "Invalid or malformed request body."


class MissingParameterError(CLUServiceError):
    """Raised when required parameters are missing."""
    status_code = 400
    message = "Required parameters are missing."


class CosmosDBError(CLUServiceError):
    """Raised when there's an error in CosmosDB operations."""
    status_code = 500
    message = "An error occurred during CosmosDB operation."


class CosmosDBConnectionError(CosmosDBError):
    """Raised when CosmosDB connection fails."""
    status_code = 503
    message = "Failed to connect to CosmosDB."


class CosmosDBQueryError(CosmosDBError):
    """Raised when CosmosDB query execution fails."""
    status_code = 500
    message = "CosmosDB query execution failed."


class CosmosDBConfigurationError(CosmosDBError):
    """Raised when CosmosDB configuration is invalid."""
    status_code = 400
    message = "Invalid CosmosDB configuration."
